<template>
    <div class="component-wrap">
        <noData v-if="listAllCount == 0"></noData>
        <div class="bscroll">
            <vue-better-scroll class="wrapper"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <ul class="inform-list">
                    <li v-for="(item,index) in list"
                        :key="index"
                        :class="{'read':item.Status}">
                        <router-link :to="{path:'/informDetail',query:{id:item.ID}}">
                            <div class="inform-info">
                                <p>{{item.Title}}</p>
                                <span>{{item.IssueTime}}</span>
                            </div>
                            <x-icon type="ios-arrow-right"
                                    fill="#c8c8cd"
                                    size="26"></x-icon>
                        </router-link>
                    </li>
                </ul>
            </vue-better-scroll>
        </div>
        <myMenu addPath="/addInform"></myMenu>
    </div>
</template>
<script>
import VueBetterScroll from 'vue2-better-scroll'
import myMenu from '@/commonComponents/menu'
export default {
    name: 'inform',
    components: {
        VueBetterScroll,
        myMenu
    },
    data () {
        return {
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            listAllCount: 0,
            listCount: 0,
            pageIndex: 0,
            list: []
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo'))
    },
    mounted () {
        this.onPullingDown()
    },
    methods: {
        onPullingDown () {
            // 模拟下拉刷新
            this.listCount = 0
            this.pageIndex = 0
            this.list = []
            this.getAffiche()
        },
        onPullingUp () {
            this.pageIndex++
            this.getAffiche()
        },
        getAffiche () { // 获取通知公告
            var params = {
                'business': 'GetAffiche',
                'data': {},
                'pageIndex': this.pageIndex,
                'pageSize': 10,
                'userId': this.userInfo.userid
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data.result)
                        this.listAllCount = res.data.count
                        this.listCount = this.list.length
                    }
                    if (this.listCount < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }).catch((response) => {
                })
        }
    }
}
</script>
<style scoped>
.component-wrap,
.bscroll {
    height: 100%;
}
.inform-list a {
    display: flex;
    justify-content: space-between;
    padding: 0 15px 0 20px;
    line-height: 50px;
    border-bottom: 1px solid #efeff4;
    align-items: center;
}
.inform-info {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.inform-info {
    font-size: 14px;
    color: #333;
}
.inform-info p {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.read .inform-info p,
.read .inform-info span {
    color: #999;
}
</style>
